package com.aclass.xqx.classscreen.db;

import com.aclass.xqx.classscreen.BaseApplication;

import java.util.List;

/**
 * Created by xqx on 2017/10/27.
 * 数据库操作
 */

public class CardDao {

    /**
     * @param shop
     * 添加卡号
     */
    public static void insertCard(Cardnumber shop) {
        BaseApplication.getDaoInstant().getCardnumberDao().insertOrReplace(shop);
    }

    /**
     * @param id
     * @return 返回搜到的id的卡号数据
     * 查询卡号id
     */
    public static List<Cardnumber> queryLove(String id) {
        return BaseApplication.getDaoInstant().getCardnumberDao().queryBuilder().where(CardnumberDao.Properties.Cardnumber.eq(id)).list();
    }
    public static List<Cardnumber> queryLoveID(String id) {
        return BaseApplication.getDaoInstant().getCardnumberDao().queryBuilder().where(CardnumberDao.Properties.Id.eq(id)).list();
    }

    /**
     * @param student_card
     * 添加学生
     */
    public static void insertStuden(CardStudent student_card){
        BaseApplication.getDaoInstant().getCardStudentDao().insertOrReplace(student_card);
    }

    /**
     * @return 返回学生数据
     */
    public static List<CardStudent> queryStudent() {
        return BaseApplication.getDaoInstant().getCardStudentDao().queryBuilder().list();
    }
    /**
     * @param id
     * @return 返回指定id的学生数据
     */
    public static List<CardStudent> queryStudentId(String id) {
        return BaseApplication.getDaoInstant().getCardStudentDao().queryBuilder().where(CardStudentDao.Properties.Id.eq(id)).list();
    }
    public static List<CardStudent> queryStudentHonor(int id,int tid) {
        return BaseApplication.getDaoInstant().getCardStudentDao().queryBuilder().where(CardStudentDao.Properties.Honor_id.notEq(id)).where(CardStudentDao.Properties.Honor_id.notEq(tid)).list();
    }
    public static void updateStudent(CardStudent shop) {
        BaseApplication.getDaoInstant().getCardStudentDao().update(shop);
    }

    /**
     * @param shop
     * 添加老师
     */
    public static void insertTeacher(CardTeacher shop) {
        BaseApplication.getDaoInstant().getCardTeacherDao().insertOrReplace(shop);
    }

    /**
     * @return 返回老师数据
     */
    public static List<CardTeacher> queryTeacher() {
        return BaseApplication.getDaoInstant().getCardTeacherDao().queryBuilder().list();
    }

    /**
     * @param teacher_no
     * @return 返回指定id的老师数据
     */
    public static List<CardTeacher> queryTeacherId(String teacher_no) {
        return BaseApplication.getDaoInstant().getCardTeacherDao().queryBuilder().where(CardTeacherDao.Properties.Id.eq(teacher_no)).list();
    }

    /**
     * @param shop
     * 添加课程表
     */
    public static void insertSchedule(ClassSchedule shop) {
        BaseApplication.getDaoInstant().getClassScheduleDao().insertOrReplace(shop);
    }

    /**
     * @return 返回课程表数据
     */
    public static List<ClassSchedule> querySchedule() {
        return BaseApplication.getDaoInstant().getClassScheduleDao().queryBuilder().list();
    }
    /**
     * @param id
     * @return 返回课程表的当天的课程表
     */

    public static List<ClassSchedule> queryscheduleWeek(String id) {
        return BaseApplication.getDaoInstant().getClassScheduleDao().queryBuilder().where(ClassScheduleDao.Properties.Week_day.eq(id)).orderAsc(ClassScheduleDao.Properties.Start_time).list();
    }

    /**
     * @param id
     * @return 返回指定id的课程表
     */
    public static List<ClassSchedule> queryscheduleId(String id) {
        return BaseApplication.getDaoInstant().getClassScheduleDao().queryBuilder().where(ClassScheduleDao.Properties.Id.eq(id)).list();
    }


    /**
     * @param shop
     * 添加校园和公告动态
     */
    public static void insertDynamic(Dynamic shop) {
        BaseApplication.getDaoInstant().getDynamicDao().insertOrReplace(shop);
    }
    /**
     * @param shop
     * 添加校园和公告动态
     */
    public static void insertDynamicScool(DynamicSchool shop) {
        BaseApplication.getDaoInstant().getDynamicSchoolDao().insertOrReplace(shop);
    }

    /**
     * @return 返回动态数据
     */
    public static List<DynamicSchool> queryArtschool() {
        return BaseApplication.getDaoInstant().getDynamicSchoolDao().queryBuilder().list();
    }
    /**
     * @return 返回动态数据
     */
    public static List<DynamicSchool> queryArtschoolId(String id) {
        return BaseApplication.getDaoInstant().getDynamicSchoolDao().queryBuilder().where(DynamicSchoolDao.Properties.Id.eq(id)).list();
    }
    /**
     * @return 返回动态数据
     */
    public static List<Dynamic> queryArtClass() {
        return BaseApplication.getDaoInstant().getDynamicDao().queryBuilder().list();
    }
    /**
     * @param id
     * @return 返回指定id的动态数据
     */
    public static List<Dynamic> queryArtClasslId(String id) {
        return BaseApplication.getDaoInstant().getDynamicDao().queryBuilder().where(DynamicDao.Properties.Id.eq(id)).orderDesc(DynamicDao.Properties.Add_time).list();
    }

    /**
     * @param shop
     * 添加轮播图和班级荣誉相册
     */
    public static void insertAlbum(ClassAlbum shop) {
        BaseApplication.getDaoInstant().getClassAlbumDao().insertOrReplace(shop);
    }

    /**
     * @return 返回轮播图和班级荣誉相册图片
     */
    public static List<ClassAlbum> queryAlbum() {
        return BaseApplication.getDaoInstant().getClassAlbumDao().queryBuilder().list();
    }
    /**
     * @param tid
     * @return 区分轮播图和班级荣誉图片
     */
    public static List<ClassAlbum> queryAlbumTid(String tid) {
        return BaseApplication.getDaoInstant().getClassAlbumDao().queryBuilder().where(ClassAlbumDao.Properties.Typeid.eq(tid)).orderDesc(ClassAlbumDao.Properties.Addtime).list();
    }

    /**
     * @param id
     * @return 返回指定id的图片
     */
    public static List<ClassAlbum> queryAlbumId(String id) {
        return BaseApplication.getDaoInstant().getClassAlbumDao().queryBuilder().where(ClassAlbumDao.Properties.Id.eq(id)).list();
    }


    /**
     * @param shop
     * 添加已读消息
     */
    public static void insertRead(ReadNews shop) {
        BaseApplication.getDaoInstant().getReadNewsDao().insertOrReplace(shop);
    }

    /**
     * @param shop
     * 添加未读消息
     */
    public static void insertNews(StudentNews shop) {
        BaseApplication.getDaoInstant().getStudentNewsDao().insertOrReplace(shop);
    }

    /**
     * @param id
     * @return 返回指定id的未读消息
     */
    public static List<StudentNews> queryNews(String id) {
        return BaseApplication.getDaoInstant().getStudentNewsDao().queryBuilder().where(StudentNewsDao.Properties.Id.eq(id)).list();
    }
    /**
     * @param sign
     * 添加签到数据
     */
    public static void insertSign(StudentSign sign) {
        BaseApplication.getDaoInstant().getStudentSignDao().insertOrReplace(sign);
    }

    /**
     * @return 返回签到数据
     */
    public static List<StudentSign> querySign() {
        return BaseApplication.getDaoInstant().getStudentSignDao().queryBuilder().list();
    }
    public static List<StudentSign> querySignId() {
        return BaseApplication.getDaoInstant().getStudentSignDao().queryBuilder().where(StudentSignDao.Properties.Signtype.eq(1)).list();
    }
    /**
     * @param shop
     * 更新签到数据
     */
    public static void updateSign(StudentSign shop) {
        BaseApplication.getDaoInstant().getStudentSignDao().update(shop);
    }

    /**
     * @param sign
     * 添加值日数据
     */
    public static void insertLabour(ClassLabour sign) {
        BaseApplication.getDaoInstant().getClassLabourDao().insertOrReplace(sign);
    }
    public static List<ClassLabour> queryLabour(){
        return BaseApplication.getDaoInstant().getClassLabourDao().queryBuilder().list();
    }
    /**
     * @param id
     * @return 返回指定id的值日生
     */
    public static List<ClassLabour> queryLabourId(String id){
        return BaseApplication.getDaoInstant().getClassLabourDao().queryBuilder().where(ClassLabourDao.Properties.Id.eq(id)).list();
    }

    /**
     * @param Week
     * @return 返回当日值日生
     */
    public static List<ClassLabour> queryLabourWeekId(String Week){
        return BaseApplication.getDaoInstant().getClassLabourDao().queryBuilder().where(ClassLabourDao.Properties.Weekday.eq(Week)).list();
    }
    /**
     * 删除
     */
    public static void deleteAll(){
        BaseApplication.getDaoInstant().getCardStudentDao().deleteAll();
        BaseApplication.getDaoInstant().getStudentNewsDao().deleteAll();
        BaseApplication.getDaoInstant().getCardnumberDao().deleteAll();
        BaseApplication.getDaoInstant().getStudentSignDao().deleteAll();
        BaseApplication.getDaoInstant().getClassAlbumDao().deleteAll();
        BaseApplication.getDaoInstant().getClassLabourDao().deleteAll();
        BaseApplication.getDaoInstant().getDynamicDao().deleteAll();
        BaseApplication.getDaoInstant().getCardTeacherDao().deleteAll();
        BaseApplication.getDaoInstant().getReadNewsDao().deleteAll();
        BaseApplication.getDaoInstant().getClassScheduleDao().deleteAll();
        BaseApplication.getDaoInstant().getDynamicSchoolDao().deleteAll();
        BaseApplication.getDaoInstant().clear();
    }
}
